import 'package:imember/Util/MyColor.dart';
import 'package:imember/Widget/MyButton.dart';
import 'package:flutter/cupertino.dart';

class MyTab extends StatelessWidget {
  String tabText = "";
  bool choose = false;
  Function() onTap;

  MyTab(this.tabText, this.choose, this.onTap);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Column(children: [
        Text(tabText, style: TextStyle(color: choose ? MyColor.Black : MyColor.A0, fontSize: choose ? 15 : 13)),
        Container(
          width: 15,
          height: 2,
          margin: EdgeInsets.only(top: 4),
          decoration: BoxDecoration(color: choose ? MyColor.Red : MyColor.Transfer, borderRadius: BorderRadius.circular(1)),
        )
      ]),
      onTap: onTap,
    );
  }
}

class MyTab2 extends StatelessWidget {
  List menus = [];
  int selectPos = 0;
  Function(int selected) callback;

  MyTab2(this.menus, this.selectPos, this.callback);

  @override
  Widget build(BuildContext context) {
    List<Widget> tabs = []; //先建一个数组用于存放循环生成的widget
    for (int i = 0; i < menus.length; i++) {
      tabs.add(Expanded(
          child: Container(
              margin: EdgeInsets.all(5),
              decoration: BoxDecoration(color: selectPos == i ? MyColor.White : MyColor.Transfer, borderRadius: BorderRadius.circular(4)),
              child: TextBtn(menus[i],
                  alignment: Alignment.center,
                  style: TextStyle(fontSize: 14, color: selectPos == i ? MyColor.Red : MyColor.White), onTap: () {
                callback(i);
              }))));
    }
    return Container(
      height: 39,
      decoration: BoxDecoration(color: MyColor.Red, borderRadius: BorderRadius.circular(8)),
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: tabs),
    );
  }
}
